import type { GetTermListQueryType, GetTermListResponseType } from "../api/base.type";

const delay = (ms = 200): Promise<void> => {
    return new Promise((resolve) => setTimeout(resolve, ms));
};

const baseTermList = [
    { code: "2023-1", name: "2023-2024 第一学期" },
    { code: "2023-2", name: "2023-2024 第二学期" },
    { code: "2024-1", name: "2024-2025 第一学期" },
    { code: "2024-2", name: "2024-2025 第二学期" },
    { code: "2025-1", name: "2025-2026 第一学期" },
];

const createUniqueId = (() => {
    let seed = 0;
    return () => {
        seed += 1;
        return `term-${Date.now().toString(36)}-${seed}`;
    };
})();

export const mockGetTermList = async (
    params?: GetTermListQueryType
): Promise<GetTermListResponseType> => {
    await delay();

    const list = baseTermList.map((item) => ({
        ...item,
        id: createUniqueId(),
    }));

    return {
        list,
        currentPage: params?.currentPage ?? 1,
        numPerPage: params?.numPerPage ?? list.length,
        totalCount: list.length,
        totalPages: 1,
    };
};
